#include "USBClientConnector.h"

void USBClientConnector::destory() {

    clear();
}

void USBClientConnector::clear() {
    _status = 0;
}

std::string USBClientConnector::readValue() {

    if (_status == 4) {
        return ""; //_pReadReportCharacteristic->readValue();
    }
    return "";
}

void USBClientConnector::connectToDevice() {

    if (_status == 2) { // 已连接
        // 已连接 --> 尝试识别HID设备

        if (_cntFail++ > 3) {
            _status = -1;
            return;
        }

        bool flag = true;
        // 分析HID报表描述符
        _pCallbacks->usb_onConnect(usbNum, flag);

        if (flag) {
            if (_type == 1) {
                _keyboard_mode = 0;
                _pCallbacks->usb_onConfigDevice(usbNum, 0, (void *)_keyboard_mode); // 键盘默认为美式布局
            }

            _status = 4; // 已识别HID
        }
    }
    return;
}

void USBClientConnector::setUSBClientConnectorCallbacks(USBClientConnectorCallbacks *pCallbacks){
    _pCallbacks=pCallbacks;
}